package texture;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class TextureManager {
	private static TextureManager instance;
	private ResourceManager theResourceManager;

	private Map<Integer, ResourceLocation> mapResourceLocations = new HashMap<>();
	private List<TickableTextureObject> listTickables = new ArrayList<>();
	private Map<ResourceLocation, TextureObject> mapTextureObjects = new HashMap<>();
	private Map<ResourceLocation, TextureMap> mapTextureMaps = new HashMap<>();

	public static TextureManager get(ResourceManager theResourceManager) {
		if (instance == null) {
			instance = new TextureManager();
			instance.theResourceManager = theResourceManager;
		}
		return instance;
	}

	public boolean loadTextureMap(ResourceLocation par1ResourceLocation, TextureMap textureObject) {
		try {
			textureObject.loadTexture(this.theResourceManager);
			this.mapResourceLocations.put(Integer.valueOf(textureObject.getTextureType()), par1ResourceLocation);
			this.listTickables.add(textureObject);
			this.mapTextureObjects.put(par1ResourceLocation, textureObject);
			this.mapTextureMaps.put(par1ResourceLocation, textureObject);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
	public TextureMap getTextureMap(ResourceLocation par1ResourceLocation){
		return this.mapTextureMaps.get(par1ResourceLocation);
	}
	
	public void tick() {
		Iterator<TickableTextureObject> iterator = this.listTickables.iterator();

		while (iterator.hasNext()) {
			Tickable tickable = (Tickable) iterator.next();
			tickable.tick();
		}
	}
}
